/*
 * RationsPaceFrameBackend.java
 * Team qq 2011
 */
package com.google.code.timetrail.gui;



import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.google.code.timetrail.backend.ConsumptionRate;
import com.google.code.timetrail.backend.Control;
import com.google.code.timetrail.backend.TravelSpeed;


/**
 * @author jake.gibel@gmail.com
 * @version 1.0.0
 */
public class RationsPaceFrameBackend {
	//TODO replace numerals with constants
    /**
     * The current game's data
     */
    private final Control gameControl;

    /**
     * the consumption rate of the game
     */
    private ConsumptionRate rations;

    /**
     * the current pace of the game
     */
    private TravelSpeed pace;

    /**
     * the selected consumption rate of the game
     */
    private int selectedRations;

    /**
     * the selected pace of the game
     */
    private int selectedPace;

    /**
     * Makes a new RationsPaceFrameBackend
     * @param gameControl The game's current data
     */
    public RationsPaceFrameBackend(Control gameControl){
        this.gameControl = gameControl;
        selectedRations = -1;
        selectedPace = -1;
    }

    /**
     * 
     * @return The text that goes into the paceLabel
     */
    public String getPaceLabelText() {

        return "Select Pace: ";
    }

    /**
     * 
     * @return The text that goes into rationsLabel
     */
    public String getRationsLabelText() {

        return "Select Rations: ";
    }

    /**
     * The selection zero for the rations
     */
    private static final int RATIONSELECTIONZERO = 0;
    
    /**
     * The selection one for the rations
     */
    private static final int RATIONSELECTIONONE = 1;
    
    /**
     * The selection two for the rations
     */
    private static final int RATIONSELECTIONTWO = 2;
    
    /**
     * The selection three for the rations
     */
    private static final int RATIONSELECTIONTHREE = 3;
    
    /**
     * The selection four for the rations
     */
    private static final int RATIONSELECTIONFOUR = 4;
    
    /**
     * Change the consumption rate to the selected Index
     * @param selectedIndex the current selected Index
     */
    public void rationsListChanged(int selectedIndex) {

        selectedRations = selectedIndex;
        if(selectedIndex == RATIONSELECTIONZERO){
            rations = ConsumptionRate.NONE;
        } else if(selectedIndex == RATIONSELECTIONONE){
            rations = ConsumptionRate.BAREBONES;
        } else if(selectedIndex == RATIONSELECTIONTWO){
            rations = ConsumptionRate.MEAGER;
        } else if(selectedIndex == RATIONSELECTIONTHREE){
            rations = ConsumptionRate.NORMAL;
        } else if(selectedIndex == RATIONSELECTIONFOUR){
            rations = ConsumptionRate.WELLFED;
        }
        
    }

    /**
     * 
     * @return possible String Representations for Rations
     */
    public String[] getRationsValues() {

        return new String[] {"None ", "Bare-Bones ", "Meager ", "Normal", "Wellfed "};
    }

    /**
     * The selection zero for the pace
     */
    private static final int PACESELECTIONZERO = 0;
    
    /**
     * The selection one for the pace
     */
    private static final int PACESELECTIONONE = 1;
    
    /**
     * The selection two for the pace
     */
    private static final int PACESELECTIONTWO = 2;
    
    /**
     * The selection three for the pace
     */
    private static final int PACESELECTIONTHREE = 3;
    
    /**
     * called when Pace is changed
     * @param selectedIndex the current selected index
     */
    public void paceValueChanged(int selectedIndex) {
        selectedPace = selectedIndex;
        if(selectedIndex == PACESELECTIONZERO){
            pace = TravelSpeed.STOPPED;
        } else if(selectedIndex == PACESELECTIONONE){
            pace = TravelSpeed.MACH;
        } else if(selectedIndex == PACESELECTIONTWO){
            pace = TravelSpeed.WARP;
        } else if(selectedIndex == PACESELECTIONTHREE){
            pace = TravelSpeed.LUDICROUS;
        }

        
    }

    /**
     * @return string representations of the pace values
     */
    public String[] getPaceValues() {

        return new String[] {"Stopped", "Mach", "Warp", "Ludacris"};
    }

    /**
     * sets the pace and rations to the selected pace and rations if
     * true
     * 
     * @return true if the information is valid, false if it isn't
     */
    public boolean canPressNextButton() {
        // TODO link cards
        if(selectedPace == -1 || selectedRations == -1){
            final JFrame frame = null;
			JOptionPane.showMessageDialog(frame,
                    "Please fill in all required information.",
                    "Some fields were left empty",
                    JOptionPane.PLAIN_MESSAGE);
            return false;
        } else {

            gameControl.setPace(pace);
            gameControl.setRations(rations);
            return true;

        }
        
    }

    /**
     * @return The text that does into NextButton
     */
    public String getNextButtonText() {

        return "Next >>";
    }

    /**

     * @return The text that goes into BackButton
     */
    public String getBackButtonText() {

        return "Back <<";
    }

    /**
     * @return the string representation of RationsPaceFrameBackend
     */
    public String toString(){
    	return "Rations/Pace Frame Backend";
    }
}
